# Definition for a binary tree node.
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
root=TreeNode(3)
root.left=TreeNode(9)
root.right=TreeNode(20)
root.right.left=TreeNode(15)
root.right.right=TreeNode(7)
def minDepth(root):
    #空树的情况
    if not root:
        return 0
    path=[root]
    level=0
    flag=False
    while len(path)>0 and not flag:
        pathLen=len(path)
        level+=1
        while pathLen>0:
            node=path.pop(0)
            if node.left==None and node.right==None:
                #到达了叶子结点
                flag=True
                break
            if node.left:
                path.append(node.left)
            if node.right:
                path.append(node.right)
            pathLen-=1
    print(level)
minDepth(root)